package de.bazinga.rotw.sky;

import java.net.URL;
import java.util.concurrent.Callable;

import com.jme.image.Texture;
import com.jme.scene.Skybox;
import com.jme.scene.state.CullState;
import com.jme.util.GameTaskQueueManager;
import com.jme.util.TextureManager;

import de.bazinga.rotw.game.Game;

public class Sky {
	public static Skybox skyBox;
	
	public static Skybox setupSky(URL north, URL west, URL south, URL east, URL top, URL bottom) {
		Sky.skyBox = new Skybox("SkyBox",400,400,400);
		
		skyBox.setTexture(Skybox.Face.North, TextureManager.loadTexture(north,Texture.MinificationFilter.BilinearNearestMipMap,Texture.MagnificationFilter.Bilinear));
		skyBox.setTexture(Skybox.Face.West, TextureManager.loadTexture(west,Texture.MinificationFilter.BilinearNearestMipMap,Texture.MagnificationFilter.Bilinear));
		skyBox.setTexture(Skybox.Face.South, TextureManager.loadTexture(south,Texture.MinificationFilter.BilinearNearestMipMap,Texture.MagnificationFilter.Bilinear));
		skyBox.setTexture(Skybox.Face.East, TextureManager.loadTexture(east,Texture.MinificationFilter.BilinearNearestMipMap,Texture.MagnificationFilter.Bilinear));
		skyBox.setTexture(Skybox.Face.Up, TextureManager.loadTexture(top,Texture.MinificationFilter.BilinearNearestMipMap,Texture.MagnificationFilter.Bilinear));
		skyBox.setTexture(Skybox.Face.Down, TextureManager.loadTexture(bottom,Texture.MinificationFilter.BilinearNearestMipMap,Texture.MagnificationFilter.Bilinear));
		
		GameTaskQueueManager.getManager().update(new Callable<Object>() {
			public Object call() throws Exception {
				skyBox.preloadTextures();
				return null;
			}
        });
        
		
		CullState cullState = Game.getGame().getDisplay().getRenderer().createCullState();
		cullState.setCullFace(CullState.Face.None);
		cullState.setEnabled(true);
		skyBox.setRenderState(cullState);
		
		skyBox.updateRenderState();
		
		return skyBox;
	}
}